﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Maticsoft.Common;
using LTP.Accounts.Bus;
namespace Chizx.Web.journal
{
    public partial class Modify : Page
    {       

        		protected void Page_Load(object sender, EventArgs e)
        {
            if (null == Session["UserEntity"])
            {
                Response.Redirect("/e/Login.aspx");
            }
            if (Session["UserDegree"].ToString() == "SX")
            {
                this.txtzu_id.Enabled = false;
            }  
			if (!Page.IsPostBack)
			{
				if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
				{
					int zj_id=(Convert.ToInt32(Request.Params["id"]));
					ShowInfo(zj_id);
				}
			}
		}
			
	private void ShowInfo(int zj_id)
	{
		Chizx.BLL.JournalBll bll=new Chizx.BLL.JournalBll();
		Chizx.Model.JournalModel model=bll.GetModel(zj_id);
		this.lblzj_id.Text=model.zj_id.ToString();
		this.txtzu_id.Text=model.zu_id;
		this.txtzj_topic.Text=model.zj_topic;
		this.txtzj_context.Text=model.zj_context;
		this.txtzj_createdate.Text=model.zj_createdate.ToString();
        this.txtzj_review.Text = model.zj_review == "0" ? "暂无" : model.zj_review;
        this.txtzj_status.Text = model.zj_status == "j0" ? "未审核" : (model.zj_status == "j1" ? "已审核" : "未知状态");

	}

		public void btnSave_Click(object sender, EventArgs e)
		{
			
			string strErr="";
            string review_this = "暂无";
            if (Session["UserDegree"].ToString() != "SX")
            {
                review_this = this.txtzj_review.Text;
            }  
			if(this.txtzu_id.Text.Trim().Length==0)
			{
				strErr+="zu_id不能为空！\\n";	
			}
			if(this.txtzj_topic.Text.Trim().Length==0)
			{
				strErr+="zj_topic不能为空！\\n";	
			}
			if(this.txtzj_context.Text.Trim().Length==0)
			{
				strErr+="zj_context不能为空！\\n";	
			}
			if(!PageValidate.IsDateTime(txtzj_createdate.Text))
			{
				strErr+="zj_createdate格式错误！\\n";	
			}
            if (review_this.Trim().Length == 0)
			{
				strErr+="zj_review不能为空！\\n";	
			}
			if(this.txtzj_status.Text.Trim().Length==0)
			{
				strErr+="zj_status不能为空！\\n";	
			}

			if(strErr!="")
			{
				MessageBox.Show(this,strErr);
				return;
			}
			int zj_id=int.Parse(this.lblzj_id.Text);
			string zu_id=this.txtzu_id.Text;
			string zj_topic=this.txtzj_topic.Text;
			string zj_context=this.txtzj_context.Text;
			DateTime zj_createdate=DateTime.Parse(this.txtzj_createdate.Text);
            string zj_review = review_this;
            string zj_status = this.txtzj_status.Text == "未审核" ? "j0" : (this.txtzj_status.Text == "已审核" ? "j1" : "j2");


			Chizx.Model.JournalModel model=new Chizx.Model.JournalModel();
			model.zj_id=zj_id;
			model.zu_id=zu_id;
			model.zj_topic=zj_topic;
			model.zj_context=zj_context;
			model.zj_createdate=zj_createdate;
			model.zj_review=zj_review;
			model.zj_status=zj_status;

			Chizx.BLL.JournalBll bll=new Chizx.BLL.JournalBll();
			bll.Update(model);
			Maticsoft.Common.MessageBox.ShowAndRedirect(this,"保存成功！","list.aspx");

		}


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("list.aspx");
        }
    }
}
